package com.yfp.operation.api.factory;

import com.yfp.common.core.domain.R;
import com.yfp.operation.api.RemoteOperationService;
import com.yfp.operation.domain.*;
import com.yfp.operation.domain.EnterpriseOrderDeliveryPlanDTO;
import com.yfp.operation.domain.OrderComboGroupDTO;
import com.yfp.operation.domain.Receiver;
import com.yfp.operation.domain.RedisOrderDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class RemoteOperationFallbackFactory implements FallbackFactory<RemoteOperationService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteOperationFallbackFactory.class);

    @Override
    public RemoteOperationService create(Throwable throwable) {
        log.error("运营服务调用失败:{}", throwable.getMessage());
        return new RemoteOperationService() {

            @Override
            public R<Void> checkMachineMealAnomaly() {
                return R.fail("检查设备状态失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> orderBillCarryto() {
                return R.fail("订单入账失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> providerWithdraw() {
                return R.fail("服务商提现失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> autoMakePayment() {
                return R.fail("自动打款分账失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> checkMachineMealMinAnomaly(List<RedisOrderDetail> redisOrderDetails) {
                return null;
            }

            @Override
            public R<Void> syncGroupChat() {
                return R.fail("同步微信群列表失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> marCall() {
                return R.fail("调用pg存储过程，更新表状态失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> checkCouponPackAndUpdateAllStatus() {
                return R.fail("检测并更新所有优惠券礼包状态，更新表状态失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> clientLabel() {
                return R.fail("用户打标签失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> checkActivitySignInsAndUpdateAllStatus() {
                return R.fail("检测并更新所有打卡活动状态，更新表状态失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> checkLotteryAndUpdateAllStatus() {
                return R.fail("检测并更新所有抽奖活动状态，更新表状态失败:" + throwable.getMessage());
            }

            @Override
            public R<Void> orderRouting(String orderSn, Integer payType) {
                log.error("调用{}异常:{}", "orderRouting", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Boolean> orderWithdraw(String orderSn) {
                log.error("调用{}异常:{}", "orderWithdraw", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> orderReimburse(String orderSn, BigDecimal amountOfMoney) {
                log.error("调用{}异常:{}", "orderReimburse", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Boolean> orderMinMake(String orderId) {
                log.error("调用{}异常:{}", "orderMake", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> addReceiver(List<Receiver> receivers) {
                log.error("调用{}异常:{}", "addReceiver", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> updatePlanStatus() {
                log.error("调用{}异常:{}", "updatePlanStatus", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            /**
             * 后台退优惠券
             *
             * @return
             */
            @Override
            public R<Void> refundClientCoupon(String orderListId) {
                log.error("调用{}异常:{}", "refundClientCoupon", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> issueInviteCouponForHost(String passiveClientId) {
                log.error("调用{}异常:{}", "issueInviteCouponForHost", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> updateComboPlanStatus() {
                log.error("调用{}异常:{}", "updateComboPlanStatus", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Boolean> checkComboParticipation(String comboId) {
                log.error("调用{}异常:{}", "checkComboParticipation", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> delOperationUser(Long operationUserId, List<String> machines) {
                log.error("调用{}异常:{}", "delOperationUser", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<List<OrderComboGroupDTO>> listGroupOrderInfo(List<String> orderSn) {
                log.error("调用{}异常:{}", "listGroupOrderInfo", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> autoEnterprisePlacementPlan(EnterpriseOrderDeliveryPlanDTO enterpriseOrderVO) {
                log.error("调用{}异常:{}", "autoEnterprisePlacementPlan", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> delEnterprisePlacementPlan(String machineId) {
                log.error("调用{}异常:{}", "delEnterprisePlacementPlan", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> lotteryCount(String clientId, String price, String cityName) {
                log.error("调用{}异常:{}", "lotteryCount", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> activitySignInsCount(String userId, String cityName) {
                log.error("调用{}异常:{}", "activitySignInsCount", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> storedActivityExpire() {
                log.error("调用{}异常:{}", "storedActivityExpire", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> storedCouponExpire(Long storedActivityDetailId) {
                log.error("调用{}异常:{}", "storedCouponExpire", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> newClientPositionLabel() {
                log.error("调用{}异常:{}", "newClientPositionLabel", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> updatePositionId(String machineId) {
                log.error("调用{}异常:{}", "updatePositionId", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }

            @Override
            public R<Void> giveIntegral(String orderId) {
                log.error("调用{}异常:{}", "giveIntegral", throwable.getMessage());
                return R.fail(throwable.getMessage());
            }
        };
    }
}